/**
 * 租赁详情对话框（可用于添加和修改对话框）
 */
var CarInfoDlg = {
    data: {
        carId: "",
        carType: "",
        carColor: "",
        carPrice: "",
        carInspection: "",
        carMileage: "",
        rentMoneyOneDay: "",
        modifyId: "",
        ticketId: "",
        rentTimes: "",
        carScore: "",
        returnDate: ""
    }
};

/**
 * 表单验证
 * @returns {*}
 */
CarInfoDlg.validateForm = function () {
    return true;
};

/**
 * 关闭此对话框
 */
CarInfoDlg.close = function () {
    parent.layer.close(window.parent.car.layerIndex);
};
/**
 * 提交租赁
 */
CarInfoDlg.editSubmit = function () {
    //注意！vue的model绑定和layui有冲突！手动赋值一下！
    CarInfoDlg.data.returnDate = Feng.getLaydate();
    var ajax = new $ax(Feng.ctxPath + "/car/rent", function (data) {
        window.parent.Feng.success("租赁成功!");
        parent.parent.location.reload();
        if (window.parent.car !== undefined) {
            window.parent.car.table.refresh();
            CarInfoDlg.close();
        }
    }, function (data) {
        Feng.error("租赁失败!" + data.responseJSON.message + "!");
    });
    ajax.set(CarInfoDlg.data);
    ajax.start();
};

$(function () {
    //获取车辆信息
    var ajax = new $ax(Feng.ctxPath + "/car/getCarInfoHasReturn?carId=" + Feng.getUrlParam("carId"));
    var result = ajax.start();
    CarInfoDlg.data = result.data;
    CarInfoDlg.app = new Vue({
        el: '#rentForm',
        data: CarInfoDlg.data,
        methods: {
            submitForm: function (e) {
                e.preventDefault();
            },
            ensure: function () {
                var result = CarInfoDlg.validateForm();
                if (result === true) {
                    CarInfoDlg.editSubmit();
                } else {
                    Feng.alert(result);
                }
            },
            close: function () {
                CarInfoDlg.close();
            }
        }
    });
    //注意！vue的model绑定和layui有冲突！
    Feng.initLaydate(CarInfoDlg.data.returnDate);
});
